package com.daixu.money

import android.os.Bundle
import android.os.Handler
import android.os.Message
import android.support.v7.app.AppCompatActivity
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import qiu.niorgai.StatusBarCompat
import java.lang.ref.WeakReference

@Route(path = "/daixu/splash")
class SplashActivity : AppCompatActivity() {

    private class MyHandler(activity: SplashActivity) : Handler() {
        private val mActivity: WeakReference<SplashActivity> = WeakReference(activity)

        override fun handleMessage(msg: Message) {
            if (mActivity.get() == null) {
                return
            }
            val activity = mActivity.get()
            when (msg.what) {
                0 -> {
                    ARouter.getInstance().build("/daixu/main")
//                            .withObject("list", list)
                            .navigation()
                    activity!!.finish()
                }
                else -> {
                }
            }
        }
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        StatusBarCompat.translucentStatusBar(this, true)
        setContentView(R.layout.activity_splash)

        MyHandler(this).sendEmptyMessageDelayed(0, 1000)
    }

    override fun onDestroy() {
        //  Remove all Runnable and Message.
        MyHandler(this).removeCallbacksAndMessages(null)
        super.onDestroy()
    }
}
